﻿
<?php
chdir('../');
include( '/bus_functions/material.php' );
/*
 * Fetch all saved materials. Eddited { 9/05/2012, 16:30 }
 * Create a table, which displays dynamic all the materials. 
 */
$materials = fetch_all_materials();

if( !empty($materials) )
{
    $i = 0;
    foreach( $materials as $material )
    {
        $mat = explode( "~", $material );
        
        $id[$i] = $mat[0];
        $name[$i] = $mat[1];
        $type[$i] = $mat[2];
        $price[$i] = $mat[3];
        
        $i++;
    }
}
?>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Υλικά</title>
	    <script type="text/javascript" src="../bus_functions/javascript/material_function.js"></script>
    </head>
   
    <body onLoad="reset_data()">
		<div>
			<table>
                <tr id="top">
					<td colspan="5"><h1>Υλικά</h1></td>
                </tr>
                <tr>
                    <td width="20"><h2>Α/Α</h2></td>
                    <td width="50"><h2>Κωδικός</h2></td>
                    <td width="200"><h2>Όνομα</h2></td>
                    <td width="160"><h2>Κατηγορία</h2></td>
                    <td width="100"><h2>Τιμή</h2></td>
                </tr>
            <?php	
            if( !empty( $id ) )
            {	
                $count = 0;
                $material_number = count( $id );
               
                for( $j = 0; $j < $material_number; $j++ )
                { ?>
                <tr>
						<td width="20"><h3><?php echo $count + 1; ?></h3></td>
						<td width="50"><h3><label title="Επεξεργασία Υλικού" onclick="update_material('<?php echo $id[$j] ?>','<?php echo $name[$j] ?>','<?php echo $type[$j] ?>','<?php echo $price[$j] ?>')" ><?php echo $id[$j]; ?></label></h3></td>
						<td width="200"><h3><label title="Επεξεργασία Υλικού" onclick="update_material('<?php echo $id[$j] ?>','<?php echo $name[$j] ?>','<?php echo $type[$j] ?>','<?php echo $price[$j] ?>')" ><?php echo $name[$j]; ?></label></h3></td>
						<td width="160"><h3><?php 
												switch($type[$j])
												{	
													case 'zyme':
														$category = "Ζύμη";
													break;
													case 'sweet':
														$category = "Γλυκά Υλικά";
													break;
													case 'salty':
														$category = "Αλμυρά Υλικά";
													break;
													default:
														$category = "Άγνωστο";
												}
												echo $category; ?>
											</h3></td>
						<td width="100"><h3><?php echo $price[$j]; ?></h3></td>
				</tr>
            <?php
            $count++;
                } 
            }?>
			
			<div>
				<tr>
					<td width="20"></td>
					<td width="50" id="nameError" style="display:none">*Please enter a name</td>
					<td width="200" id="typeError" style="display:none">*Please select a category</td>
					<td width="160" id="priceError" style="display:none">*Please enter a price</td>
				</tr>
				<tr id="editBar"> 
					<td width="20"><h3><?php echo $count + 1; ?></h3></td>
					<td width="50"><h3><input type="text" id="mat_id" name="mat_id" size="4" readonly="readonly"/></h3></td>
					<td width="200"><h3><input type="text" id="name" name="name" maxlength="29"/></h3></td>
					<td width="160"><h3>
						<select id="category">
							<option value="epilogi">Επιλέξτε Κατηγορία</option>
							<option value="zyme">Ζύμη</option>
							<option value="sweet">Γλυκά Υλικά</option>
							<option value="salty">Αλμυρά Υλικά</option>
						</select></h3>
					</td>
					<td width="100"><h3><input type="text" id="price" name="price" maxlength="10" size="8"/></h3></td>
					<td><h3><input type="button" value=" + " id="add" title="Προσθήκη Υλικού" style="display:none" onclick="add_material()"/></h3></td>
					<td><h3><input type="button" value=" - " id="delete" title="Διαγραφή Υλικού" style="display:none" onclick="delete_material()"/></h3></td>
					<td><h3><input type="button" value=" x " id="close" title="Ακύρωση Επεξεργασίας" style="display:none" onclick="reset_data()"/></h3></td>
					<td><h3><input type="button" value=" Αποθήκευση " id="save" title="Αποθήκευση Υλικού" style="display:none" onclick="save_material()"/></h3></td>
				</tr>
			</div>
			</table>
		</div>	   
    </body>
</html>
<!--
<script type="text/javascript">
	function add_materia()
	{
		
	}
</script> -->